package com.hao.hospital.core;


import com.hao.hospital.controller.BackstageAction;
import com.hao.hospital.controller.DrugAction;
import com.hao.hospital.controller.MainAction;
import com.hao.hospital.controller.MedicalAction;
import com.hao.hospital.controller.OpenDrugAction;
import com.hao.hospital.controller.PaymentAction;
import com.hao.hospital.controller.PersonAction;
import com.hao.hospital.controller.UserAction;
import com.hao.hospital.controller.WeiXinAction;
import com.hao.hospital.core.param.GlobalMap;
import com.hao.hospital.model._MappingKit;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;



public class JfinalConfig extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		PropKit.use("config.txt");
		me.setDevMode(PropKit.getBoolean("devMode"));
		me.setBaseUploadPath("upload/temp/");
		//me.setBaseUploadPath("d:/fileUpload");
		GlobalMap.configMap.put("appid", PropKit.get("appid"));
		GlobalMap.configMap.put("appsecret", PropKit.get("appsecret"));
		GlobalMap.configMap.put("redirectUri", PropKit.get("wx.callback.url"));
		GlobalMap.configMap.put("scope", PropKit.get("scope"));
		GlobalMap.configMap.put("domain",PropKit.get("domain"));
		GlobalMap.configMap.put("ContextOne",PropKit.get("ContextOne"));
		GlobalMap.configMap.put("ContextTwo",PropKit.get("ContextTwo"));
		GlobalMap.configMap.put("ContextThree",PropKit.get("ContextThree"));
		GlobalMap.configMap.put("sendMessageAPI",PropKit.get("sendMessageAPI"));
		GlobalMap.configMap.put("AccessKey",PropKit.get("AccessKey"));
		GlobalMap.configMap.put("SecretKey",PropKit.get("SecretKey"));
		GlobalMap.configMap.put("bucketname",PropKit.get("bucketname"));
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/main", MainAction.class);
		me.add("/wx", WeiXinAction.class);
		me.add("/drug",DrugAction.class);
		me.add("/medical",MedicalAction.class);
		me.add("/opendrug",OpenDrugAction.class);
		me.add("/payment",PaymentAction.class);
		me.add("/person",PersonAction.class);
		me.add("/user",UserAction.class);
		me.add("/admin",BackstageAction.class);
	}
	
	@Override
	public void configPlugin(Plugins me) {
		C3p0Plugin c3p0Plugin=new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
		
		ActiveRecordPlugin arp=new ActiveRecordPlugin(c3p0Plugin);
		arp.setShowSql(PropKit.getBoolean("devMode"));
		arp.setDialect(new MysqlDialect());
		/********在此添加数据库 表-Model 映射*********/
		_MappingKit.mapping(arp);
		//添加到插件列表中
		me.add(c3p0Plugin);
		me.add(arp);
	}
	public static C3p0Plugin createC3p0Plugin() {
		return new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("contextPath"));// 设置上下文路径
		
	}
	 public static void main(String[] args) {
	        JFinal.start("src/main/webapp", 8080, "/", 5);
	    }
}
